local levDiff, levRange, r, g, b
local strformat = string.format

function Icetip:GetDifficultyColor(level)
	levDiff = level - UnitLevel("player")
	levRange = GetQuestGreenRange()--8
	if (levDiff >=5 or level == -1) then
		r = 1; g = 0.2; b = 0.2;
	elseif (levDiff >= 3) then
		r = 1; g = 0.4; b = 0;
	elseif (levDiff >=-2) then
		r = 1; g = 1; b = 0;
	elseif (-levDiff <= levRange) then
		r = 0; g = 1; b = 0;
	else
		r = 0.53; g = 0.53; b = 0.53
	end
	return strformat("%2x%2x%2x", r*255,g*255,b*255)
end


function Icetip:UnitColor(unit, bdead, tapped, reaction)
	bdead = bdead or UnitHealth(unit) <= 0 and (not bplayer or UnitIsDeadOrGhost(unit))
	--tapped
	tapped = tapped or UnitIsTapped(unit) and (not UnitIsTappedByPlayer(unit))
	reaction = reaction or UnitReaction(unit, "player")

	if tapped or bdead then
		r = 0.55; g = 0.55; b = 0.55
	elseif (UnitIsPlayer(unit) or UnitPlayerControlled(unit) ) then
		if (UnitCanAttack(unit, "player")) then
			if (not UnitCanAttack("player", unit)) then
				r=1.0; g=0.4; b=0.9
			else
				r=1.0; g=0.0; b =0.0
			end
		elseif (UnitCanAttack("player", unit)) then
			r= 1.0; g=1.0; b=0
		elseif (UnitIsPVP(unit)) then
			r = 0.0; g = 1.0; b = 0.0
		else
			r = 0.8; g = 0.7; b = 0.9
		end
	elseif reaction then
		if reaction < 4 then
			r,g,b =1,0.3,0.22
		elseif reaction > 4 then
			r,g,b = 0,1,0
		else
			r,g,b = 1,1,0
		end
	else
		r, g, b =1, 1, 1
	end

	return r,g,b
end
